package com.fjnu.service.impl;

import com.fjnu.dao.CategoryDao;
import com.fjnu.entity.Category;
import com.fjnu.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public int addCategory(Category category) {
        try {
            return categoryDao.insert(category);
        } catch (Exception e) {
            log.error("添加分类失败: {}", e.getMessage());
            throw new RuntimeException("添加分类失败", e);
        }
    }

    @Override
    public int deleteCategory(Integer categoryId) {
        try {
            return categoryDao.delete(categoryId);
        } catch (Exception e) {
            log.error("删除分类失败: {}", e.getMessage());
            throw new RuntimeException("删除分类失败", e);
        }
    }

    @Override
    public List<Category> getAllCategories() {
        try {
            return categoryDao.selectAll();
        } catch (Exception e) {
            log.error("获取分类列表失败: {}", e.getMessage());
            throw new RuntimeException("获取分类列表失败", e);
        }
    }
}